import { defineAsyncComponent } from "vue";

/**
 * 资源类型
 */
export type ResourceLibraryType = "image" | "video" | "file";

/**
 * 配置类型
 */
export interface ConfigType {
    name: string;
    limit: number;
    component: ReturnType<typeof defineAsyncComponent>;
}

/**
 * 类型配置
 */
const config: Record<ResourceLibraryType, ConfigType> = {
    image: {
        name: "图片",
        limit: 16,
        component: defineAsyncComponent(() => import("./ListTemplate/ImageList.vue")),
    },
    video: {
        name: "视频",
        limit: 10,
        component: defineAsyncComponent(() => import("./ListTemplate/VideoList.vue")),
    },
    file: {
        name: "文件",
        limit: 10,
        component: defineAsyncComponent(() => import("./ListTemplate/FileList.vue")),
    },
};

/**
 * 获取资源分类
 */
export function getResCateType(): Array<{ label: string; value: ResourceLibraryType }> {
    return Object.entries(config).map(([key, value]) => ({
        label: value.name,
        value: key as ResourceLibraryType,
    }));
}

/**
 * 获取模板组件
 */
export function ComponentData(): Record<string, ReturnType<typeof defineAsyncComponent>> {
    return Object.fromEntries(
        Object.entries(config).map(([key, value]) => [`${key}-list`, value.component])
    );
}

export default config;